package com.ruoyi.web.controller.pc;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.MyProject;
import com.ruoyi.web.service.MyProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * @author : GuitarXiaohe
 * @version V1.0
 * @Project: serve
 * @Package com.ruoyi.web.controller
 * @Description: MyProjectController
 * @date Date : 2023年10月25日 15:28
 */

@RestController
@RequestMapping("/system/project")
public class MyProjectController extends BaseController {

    @Resource
    private MyProjectService myProjectService;

    /**
     * 查询我的项目列表
     */
    @PreAuthorize("@ss.hasPermi('web:project:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyProject myProject)
    {
        startPage();
        List<MyProject> list = myProjectService.selectMyProjectList(myProject);
        return getDataTable(list);
    }

    /**
     * 导出我的项目列表
     */
    @PreAuthorize("@ss.hasPermi('web:project:export')")
    @Log(title = "我的项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyProject myProject)
    {
        List<MyProject> list = myProjectService.selectMyProjectList(myProject);
        ExcelUtil<MyProject> util = new ExcelUtil<MyProject>(MyProject.class);
        util.exportExcel(response, list, "我的项目数据");
    }

    /**
     * 获取我的项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('web:project:query')")
    @GetMapping(value = "/{projectId}")
    public AjaxResult getInfo(@PathVariable("projectId") Long projectId)
    {
        return AjaxResult.success(myProjectService.selectMyProjectByProjectId(projectId));
    }

    /**
     * 新增我的项目
     */
    @PreAuthorize("@ss.hasPermi('web:project:add')")
    @Log(title = "我的项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyProject myProject)
    {
        return toAjax(myProjectService.insertMyProject(myProject));
    }

    /**
     * 修改我的项目
     */
    @PreAuthorize("@ss.hasPermi('web:project:edit')")
    @Log(title = "我的项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyProject myProject)
    {
        return toAjax(myProjectService.updateMyProject(myProject));
    }

    /**
     * 删除我的项目
     */
    @PreAuthorize("@ss.hasPermi('web:project:remove')")
    @Log(title = "我的项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds)
    {
        return toAjax(myProjectService.deleteMyProjectByProjectIds(projectIds));
    }
}